<template>
  <div class="button">
    <div ref="box" class="box">
      <span>全部</span>
      <span>可下载</span>
      <div class="slider">全部</div>
    </div>
  </div>
</template>

<script>
export default {
  props: ["download"],
  mounted() {
    this.$nextTick(() => {
      if (!this.download) {
        this.$refs.box.classList.remove("active");
        this.$refs.box.querySelector(".slider").innerText = "全部";
      } else {
        this.$refs.box.classList.add("active");
        this.$refs.box.querySelector(".slider").innerText = "可下载";
      }
    });
  },
  watch: {
    download: function (n) {
      if (!n) {
        this.$refs.box.classList.remove("active");
        this.$refs.box.querySelector(".slider").innerText = "全部";
      } else {
        this.$refs.box.classList.add("active");
        this.$refs.box.querySelector(".slider").innerText = "可下载";
      }
    },
  },
};
</script>

<style lang="less" scoped>
.button {
  .box {
    width: 110px;
    display: flex;
    justify-content: space-between;
    padding: 0 10px;
    align-items: center;
    background-color: #f7f7f7;
    height: 30px;
    border-radius: 30px;
    font-size: 14px;
    color: #aaa;
    position: relative;

    &.active {
      .slider {
        left: 47px;
        width: 60px;
      }
    }
    .slider {
      transition: 0.5s;
      position: absolute;
      height: 26px;
      background-color: #fff;
      border-radius: 26px;
      width: 50px;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #000;
      font-size: 13px;
      left: 3px;
      font-weight: 550;
    }
  }
}
</style>